package com.zongxingh.falcon.logger.reader;

import com.google.gson.Gson;
import com.zongxingh.falcon.logger.common.SimpleLog;
import com.zongxingh.falcon.logger.config.LoggerProperties;
import com.zongxingh.falcon.mq.config.MqProperties;
import com.zongxingh.falcon.mq.consumer.MsgConsume;
import com.zongxingh.falcon.mq.entity.SimpleMessage;

import java.util.List;

/**
 * Introduction:  <简介>
 * Package Name:  com.zongxingh.falcon.logger.reader
 * Project Name:  falcon-logger
 * Author:  zongxingh
 * Email： zongxingh@163.com
 * Tel: 157*****778
 * Create Time:  2020/10/29 9:56
 */
public abstract class AbstractLogReader implements MsgConsume{

    private LoggerProperties loggerProperties;

    private MqProperties mqProperties;

    public AbstractLogReader(){}

    public AbstractLogReader( MqProperties mqProperties,LoggerProperties loggerProperties) {
        this.loggerProperties = loggerProperties;
        this.mqProperties = mqProperties;
    }

    public LoggerProperties getLoggerProperties() {
        return loggerProperties;
    }

    public void setLoggerProperties(LoggerProperties loggerProperties) {
        this.loggerProperties = loggerProperties;
    }

    public MqProperties getMqProperties() {
        return mqProperties;
    }

    public void setMqProperties(MqProperties mqProperties) {
        this.mqProperties = mqProperties;
    }

    @Override
    public boolean consumeMessages(List<SimpleMessage> messageList) {
        if (null == messageList || messageList.size() == 0){
            return true;
        }
        SimpleMessage simpleMessage = messageList.get(0);
        if (null != simpleMessage){
            Gson gson = new Gson();
            SimpleLog simpleLog = gson.fromJson(simpleMessage.getMsg(),SimpleLog.class);
            this.readerLog(simpleLog);
            return true;
        }
        return true;
    }

    public abstract void readerLog(SimpleLog simpleLog);
}
